package org.tuling.tlmallusersentineldemo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.tuling.tlmallcommon.Result;
import org.tuling.tlmallusersentineldemo.feign.OrderFeignService;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController{

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private OrderFeignService orderService;

    @RequestMapping(value = "/getOrder")
    public Result<?> getOrderByUserId(@RequestParam("userId") String userId) {
        //log.info("根据userId:"+userId+"查询订单信息");

        //利用@LoadBalanced，restTemplate需要添加@LoadBalanced注解
//        String url = "http://tlmall-order-sentinel-demo/order/getOrder?userId="+userId;
//        Result result = restTemplate.getForObject(url,Result.class);

        //使用openFeign调用订单服务
        Result result = orderService.getOrder(userId);

        return result;
    }



}